Vue.config.productionTip = false;

new Vue({
  el: "#app",
  data: {
    date: "2023-3-31",
    lunarDate: "2023-2-10",
    festival: null,
    lunarFestival: null,
    lYear: 2023,
    lMonth: 2,
    lDay: 10,
    Animal: "兔",
    IMonthCn: "闰二月",
    IDayCn: "初十",
    cYear: 2023,
    cMonth: 3,
    cDay: 31,
    gzYear: "癸卯",
    gzMonth: "乙卯",
    gzDay: "戊子",
    isToday: true,
    isLeap: true,
    nWeek: 5,
    ncWeek: "星期五",
    isTerm: false,
    Term: null,
    astro: "白羊座",
    五行: "水",
    相克: {},
    相生: {},
    被克: {},
    被生: {},
    颜色: {},
  },
  mounted() {
    this.calcColorFn();
    setInterval(() => {
      this.calcColorFn();
    }, 60000);
  },
  computed: {
    dateShow() {
      return dayjs(this.date).format("YYYY-MM-DD");
    },
  },
  methods: {
    calcColorFn(nowDate = dayjs()) {
      const result = calendar.solar2lunar(
        nowDate.year(),
        nowDate.month() + 1,
        nowDate.date()
      );
      const [天干, 地支] = result.gzDay;
      const 五行 = 地支对应表[地支];

      Object.assign(this, result);
      Object.assign(this, window[五行]);
    },
    handleDateChange(e) {
      this.calcColorFn(dayjs(e.target.value));
    },
    current() {
      this.calcColorFn();
    },
    pre() {
      this.calcColorFn(dayjs(this.date).add(-1, "day"));
    },
    next() {
      this.calcColorFn(dayjs(this.date).add(1, "day"));
    },
  },
});
